import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    component: () => import('../views/Index.vue'),
    children: [{
        path: '/',
        redirect: 'home'
      },{
        path: 'home',
        component: () => import('../components/section/home.vue'),
        meta: {title: 'WIT社区'}
      },{
        path: 'chat',
        component: () => import('../components/section/chatHall.vue'),
        children: [{
          path: '/',
          component: () => import('../components/chat/chat.vue'),
          meta: {title: '聊天大厅'}
        }]
      },{
        path: 'article',
        component: () => import('../components/section/article.vue'),
        children: [{
          path: '/',
          component: () => import('../components/article/all.vue'),
          meta: {title: '精选文章'}
        },{
          path: ':id',
          component: () => import('../components/article/articleDetail.vue')
        }]
      },{
        path: 'topic',
        component: () => import('../components/section/topic.vue'),
        children: [{
          path: '/',
          component: () => import('../components/topics/all.vue'),
          meta: {title: '话题社区'}
        },{
          path: ':id',
          component: () => import('../components/topics/topicsDetail.vue')
        }]
      },{
        path: 'about',
        component: () => import('../components/section/about.vue'),
        meta: {title: '关于我们'}
      }
    ]
  },{
    path: '/User',
    component: () => import('../views/User.vue'),
    meta: {title: '个人中心'},
    children: [{
        path: '/',
        redirect: 'info'
      },{
        path: 'info',
        meta: {title: '个人信息'},
        component: () => import('../components/user/info.vue')
      },{
        path: 'article',
        component: () => import('../components/user/article.vue'),
        children: [{
          path: '/',
          meta: {title: '我的文章'},
          component: () => import('../components/user/article/infoarticle.vue')
        },{
          path: 'uploadArticle',
          meta: {title: '上传文章'},
          component: () => import('../components/user/article/uparticle.vue')
        }]
      },{
        path: 'topics',
        component: () => import('../components/user/topics.vue'),
        children: [{
          path: '/',
          meta: {title: '我的话题'},
          component: () => import('../components/user/topics/infotopics.vue')
        },{
          path: 'uploadTopics',
          meta: {title: '发起话题'},
          component: () => import('../components/user/topics/uptopics.vue')
        }]
      },{
        path: 'collect',
        component: () => import('../components/user/collect.vue'),
        meta: {title: '我的收藏'}
      },{
        path: 'attention',
        component: () => import('../components/user/attention/attention.vue'),
        meta: {title: '关注好友'}
      }
    ]
  },{
    path: '/Admin',
    component: () => import('../views/Admin.vue'),
    children: [{
      path: '/',
      component: () => import('../components/admin/login.vue'),
      meta: {title: 'WIT社区后台管理系统'}
    },{
      path: 'home',
      component: () => import('../components/admin/home.vue'),
      meta: {title: 'WIT社区后台管理系统'},
      children: [{
        path: 'audit',
        component: () => import('../components/admin/content/audit/audit.vue'),
        meta: {title: '文章审核'}
      },{
        path: 'article',
        component: () => import('../components/admin/content/article/article.vue'),
        meta: {title: '文章操作'}
      },{
        path: 'report',
        component: () => import('../components/admin/content/report/report.vue'),
        meta: {title: '举报记录'}
      },{
        path: 'setting',
        component: () => import('../components/admin/content/home/setting.vue'),
        meta: {title: '主页设置'}
      }]
    }]
  },{
    path: '/Room',
    name: 'room',
    component: () => import('../components/chat/room/room.vue'),
    meta: {title: '房间'}
  },{
    path: '*',
    component: () => import('../components/info/404.vue'),
    meta: {title:'找不到页面'}
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.afterEach((to)=>{
  document.title = to.meta.title || ''
})

export default router
